import 'package:finance_app/src/entities/current_subscription_entity.dart';

currentSubscriptionEntityFromJson(CurrentSubscriptionEntity data, Map<String, dynamic> json) {
	if (json['plan'] != null) {
		data.plan = CurrentSubscriptionPlan().fromJson(json['plan']);
	}
	if (json['subscription'] != null) {
		data.subscription = CurrentSubscriptionSubscription().fromJson(json['subscription']);
	}
	if (json['is_renew_failed'] != null) {
		data.isRenewFailed = json['is_renew_failed'] is String
				? int.tryParse(json['is_renew_failed'])
				: json['is_renew_failed'].toInt();
	}
	if (json['is_transaction_over_limit'] != null) {
		data.isTransactionOverLimit = json['is_transaction_over_limit'] is String
				? int.tryParse(json['is_transaction_over_limit'])
				: json['is_transaction_over_limit'].toInt();
	}
	if (json['is_trial'] != null) {
		data.isTrial = json['is_trial'] is String
				? int.tryParse(json['is_trial'])
				: json['is_trial'].toInt();
	}
	if (json['flag'] != null) {
		data.flag = json['flag'] is String
				? int.tryParse(json['flag'])
				: json['flag'].toInt();
	}
	if (json['promos'] != null) {
		data.promos = (json['promos'] as List).map((v) => PromoEntity().fromJson(v)).toList();
	}
	if (json['messages'] != null) {
		data.messages = (json['messages'] as List).map((v) => MessageEntity().fromJson(v)).toList();
	}
	return data;
}

Map<String, dynamic> currentSubscriptionEntityToJson(CurrentSubscriptionEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['plan'] = entity.plan?.toJson();
	data['subscription'] = entity.subscription?.toJson();
	data['is_renew_failed'] = entity.isRenewFailed;
	data['is_transaction_over_limit'] = entity.isTransactionOverLimit;
	data['is_trial'] = entity.isTrial;
	data['flag'] = entity.flag;
	data['promos'] =  entity.promos?.map((v) => v.toJson())?.toList();
	data['messages'] =  entity.messages?.map((v) => v.toJson())?.toList();
	return data;
}

promoEntityFromJson(PromoEntity data, Map<String, dynamic> json) {
	if (json['title'] != null) {
		data.title = json['title'].toString();
	}
	if (json['content'] != null) {
		data.content = json['content'].toString();
	}
	return data;
}

Map<String, dynamic> promoEntityToJson(PromoEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['title'] = entity.title;
	data['content'] = entity.content;
	return data;
}

messageEntityFromJson(MessageEntity data, Map<String, dynamic> json) {
	if (json['type'] != null) {
		data.type = json['type'].toString();
	}
	if (json['info'] != null) {
		data.info = json['info'].toString();
	}
	return data;
}

Map<String, dynamic> messageEntityToJson(MessageEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['type'] = entity.type;
	data['info'] = entity.info;
	return data;
}

currentSubscriptionPlanFromJson(CurrentSubscriptionPlan data, Map<String, dynamic> json) {
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['type'] != null) {
		data.type = json['type'].toString();
	}
	if (json['name'] != null) {
		data.name = json['name'].toString();
	}
	if (json['name_text'] != null) {
		data.nameText = json['name_text'].toString();
	}
	if (json['price'] != null) {
		data.price = json['price'].toString();
	}
	if (json['price_text'] != null) {
		data.priceText = json['price_text'].toString();
	}
	if (json['description'] != null) {
		data.description = json['description'].toString();
	}
	if (json['transaction_limit'] != null) {
		data.transactionLimit = json['transaction_limit'] is String
				? int.tryParse(json['transaction_limit'])
				: json['transaction_limit'].toInt();
	}
	if (json['transaction_count'] != null) {
		data.transactionCount = json['transaction_count'];
	}
	if (json['is_current_subscribed'] != null) {
		data.isCurrentSubscribed = json['is_current_subscribed'];
	}
	return data;
}

Map<String, dynamic> currentSubscriptionPlanToJson(CurrentSubscriptionPlan entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['id'] = entity.id;
	data['type'] = entity.type;
	data['name'] = entity.name;
	data['name_text'] = entity.nameText;
	data['price'] = entity.price;
	data['price_text'] = entity.priceText;
	data['description'] = entity.description;
	data['transaction_limit'] = entity.transactionLimit;
	data['transaction_count'] = entity.transactionCount;
	data['is_current_subscribed'] = entity.isCurrentSubscribed;
	return data;
}

currentSubscriptionSubscriptionFromJson(CurrentSubscriptionSubscription data, Map<String, dynamic> json) {
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['coupon_id'] != null) {
		data.couponId = json['coupon_id'];
	}
	if (json['user_id'] != null) {
		data.userId = json['user_id'] is String
				? int.tryParse(json['user_id'])
				: json['user_id'].toInt();
	}
	if (json['payment_gateway_id'] != null) {
		data.paymentGatewayId = json['payment_gateway_id'];
	}
	if (json['company_id'] != null) {
		data.companyId = json['company_id'] is String
				? int.tryParse(json['company_id'])
				: json['company_id'].toInt();
	}
	if (json['plan_id'] != null) {
		data.planId = json['plan_id'] is String
				? int.tryParse(json['plan_id'])
				: json['plan_id'].toInt();
	}
	if (json['start_at'] != null) {
		data.startAt = json['start_at'].toString();
	}
	if (json['end_at'] != null) {
		data.endAt = json['end_at'].toString();
	}
	if (json['issued_at'] != null) {
		data.issuedAt = json['issued_at'].toString();
	}
	if (json['due_at'] != null) {
		data.dueAt = json['due_at'];
	}
	if (json['notified_at'] != null) {
		data.notifiedAt = json['notified_at'];
	}
	if (json['renew'] != null) {
		data.renew = json['renew'] is String
				? int.tryParse(json['renew'])
				: json['renew'].toInt();
	}
	if (json['bill_to_company_id'] != null) {
		data.billToCompanyId = json['bill_to_company_id'];
	}
	if (json['bill_phone_number'] != null) {
		data.billPhoneNumber = json['bill_phone_number'];
	}
	if (json['bill_contact_name'] != null) {
		data.billContactName = json['bill_contact_name'];
	}
	if (json['bill_postal_code'] != null) {
		data.billPostalCode = json['bill_postal_code'];
	}
	if (json['bill_unit_number'] != null) {
		data.billUnitNumber = json['bill_unit_number'];
	}
	if (json['bill_address'] != null) {
		data.billAddress = json['bill_address'];
	}
	if (json['bill_company_name'] != null) {
		data.billCompanyName = json['bill_company_name'];
	}
	if (json['bill_country_code'] != null) {
		data.billCountryCode = json['bill_country_code'];
	}
	if (json['payment_gateway_status'] != null) {
		data.paymentGatewayStatus = json['payment_gateway_status'];
	}
	if (json['payment_method'] != null) {
		data.paymentMethod = json['payment_method'];
	}
	if (json['card_number'] != null) {
		data.cardNumber = json['card_number'];
	}
	if (json['next_price'] != null) {
		data.nextPrice = json['next_price'] is String
				? int.tryParse(json['next_price'])
				: json['next_price'].toInt();
	}
	if (json['price'] != null) {
		data.price = json['price'] is String
				? int.tryParse(json['price'])
				: json['price'].toInt();
	}
	if (json['original_price'] != null) {
		data.originalPrice = json['original_price'] is String
				? int.tryParse(json['original_price'])
				: json['original_price'].toInt();
	}
	if (json['status'] != null) {
		data.status = json['status'].toString();
	}
	if (json['created_at'] != null) {
		data.createdAt = json['created_at'].toString();
	}
	if (json['updated_at'] != null) {
		data.updatedAt = json['updated_at'].toString();
	}
	if (json['deleted_at'] != null) {
		data.deletedAt = json['deleted_at'];
	}
	if (json['plan'] != null) {
		data.plan = CurrentSubscriptionSubscriptionPlan().fromJson(json['plan']);
	}
	return data;
}

Map<String, dynamic> currentSubscriptionSubscriptionToJson(CurrentSubscriptionSubscription entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['id'] = entity.id;
	data['coupon_id'] = entity.couponId;
	data['user_id'] = entity.userId;
	data['payment_gateway_id'] = entity.paymentGatewayId;
	data['company_id'] = entity.companyId;
	data['plan_id'] = entity.planId;
	data['start_at'] = entity.startAt;
	data['end_at'] = entity.endAt;
	data['issued_at'] = entity.issuedAt;
	data['due_at'] = entity.dueAt;
	data['notified_at'] = entity.notifiedAt;
	data['renew'] = entity.renew;
	data['bill_to_company_id'] = entity.billToCompanyId;
	data['bill_phone_number'] = entity.billPhoneNumber;
	data['bill_contact_name'] = entity.billContactName;
	data['bill_postal_code'] = entity.billPostalCode;
	data['bill_unit_number'] = entity.billUnitNumber;
	data['bill_address'] = entity.billAddress;
	data['bill_company_name'] = entity.billCompanyName;
	data['bill_country_code'] = entity.billCountryCode;
	data['payment_gateway_status'] = entity.paymentGatewayStatus;
	data['payment_method'] = entity.paymentMethod;
	data['card_number'] = entity.cardNumber;
	data['next_price'] = entity.nextPrice;
	data['price'] = entity.price;
	data['original_price'] = entity.originalPrice;
	data['status'] = entity.status;
	data['created_at'] = entity.createdAt;
	data['updated_at'] = entity.updatedAt;
	data['deleted_at'] = entity.deletedAt;
	data['plan'] = entity.plan?.toJson();
	return data;
}

currentSubscriptionSubscriptionPlanFromJson(CurrentSubscriptionSubscriptionPlan data, Map<String, dynamic> json) {
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['type'] != null) {
		data.type = json['type'].toString();
	}
	if (json['name'] != null) {
		data.name = json['name'].toString();
	}
	if (json['icon'] != null) {
		data.icon = json['icon'].toString();
	}
	if (json['transaction_limit'] != null) {
		data.transactionLimit = json['transaction_limit'] is String
				? int.tryParse(json['transaction_limit'])
				: json['transaction_limit'].toInt();
	}
	if (json['price'] != null) {
		data.price = json['price'].toString();
	}
	if (json['status'] != null) {
		data.status = json['status'].toString();
	}
	if (json['created_at'] != null) {
		data.createdAt = json['created_at'].toString();
	}
	if (json['updated_at'] != null) {
		data.updatedAt = json['updated_at'].toString();
	}
	return data;
}

Map<String, dynamic> currentSubscriptionSubscriptionPlanToJson(CurrentSubscriptionSubscriptionPlan entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['id'] = entity.id;
	data['type'] = entity.type;
	data['name'] = entity.name;
	data['icon'] = entity.icon;
	data['transaction_limit'] = entity.transactionLimit;
	data['price'] = entity.price;
	data['status'] = entity.status;
	data['created_at'] = entity.createdAt;
	data['updated_at'] = entity.updatedAt;
	return data;
}